Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

294
Visualizações
How do I make a discord-bot stop replying after I write "shut up"?

I started on this small project just for fun for my friend's server. She wanted to have the bot reply to her any time she said anything in her server and she wanted the bot to stop replying after an hour after saying "shut up" (no prefixes). I currently have this

client.on("message", function (message) {
const amyID = "blahblah";
const jayID = "blahblah";
if (message.author.id == (jayID)) {
    if (message.content.includes("shut up")) {
        message.reply("sorry...")
        setTimeout(function () {

        }, 60000)
    } else {
        client.commands.get('replyToAmy').execute(message);
    }
  }
})

setTimeout seems to only work with functions which I am confused on how I can apply it to the client.on bit. If I remove setTimeout the bot will start responding again. How can I make the bot stop responding for a set amount of time after "shut up" is said by the user?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

One way to do that would be create a boolean variable outside the client.on('message') function. Then the bot will keep sending a message as long as the boolean variable is set to true. Once the user tells the bot to stop, the boolean variable is set to false and you can create a .setTimeout() for the specified time after which the boolean variable will turn back to true. And then all we have to do is check if the boolean variable is true or not every time we send the message. The code might look something like this:

let keepReplying = true
const userId = 'the users id'
client.on('message', message => {
    if (message.author.id === userId) {
        if (message.content === 'stop') {
            keepReplying = false
            setTimeout(() => { keepReplying = true }, 60000)
        }
    }
    if (keepReplying) client.commands.get('replyToAmy').execute(message);
})
about 4 years ago · Juan Pablo Isaza Relatório

0

Maybe Create a list to contain the user who said shut up & timestamp then function to check user from that list and compare time with timestamp?

well if user timestamp > 1 hr then delete that from the list

there's a better way tho but this is the easy route. and not the most effective way as it would be too much waste with many users

but from your code seem like you just made small project for small group of users so there's no problem

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda